from multiprocessing import Process
import mmap
import contextlib
import time


def reader():
    while True:
        time.sleep(0.5)
        invalid_byte, empty_byte = str.encode('\x00'), str.encode('')
        with contextlib.closing(mmap.mmap(-1, 1024, tagname='cnblogs', access=mmap.ACCESS_READ)) as mem:
            share_data = mem.read(1024).replace(invalid_byte, empty_byte)
            if share_data:
                print("Get data:== %s == from share memory!" % share_data.decode())


if __name__ == '__main__':
    p_reader = Process(target=reader, args=())
    p_reader.start()
    p_reader.join()
